package com.taxshare.operation.service;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.taxshare.mybatis.pager.PageHelp;
import com.taxshare.mybatis.pager.PageRequest;
import com.taxshare.mybatis.utils.DozerBeanUtil;
import com.taxshare.operation.entity.MessageTemplateEntity;
import com.taxshare.operation.mapper.MessageTemplateMapper;
import com.taxshare.operation.view.vo.MessageTemplateVO;
import com.taxshare.response.beans.Response;
import com.taxshare.tools.util.UUIDUitl;

/**
    * @ClassName: MessageTemplateService
    * @Description: (消息模板)
    * @author liupp
    * @date 2021年1月22日
    *
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED)
public class MessageTemplateService extends ServiceImpl<MessageTemplateMapper, MessageTemplateEntity>{

	/**
     * @Title: getDetailInfoList
     * @Description: (分页)
     * @param @param codeDetailVO
     * @param @return    参数
     * @return Response<List<MessageTemplateVO>>    返回类型
     * @throws
  */
 public Response<IPage<MessageTemplateVO>> queryPageList(PageRequest<MessageTemplateVO> query){
 	QueryWrapper<MessageTemplateEntity> queryWrapper = new QueryWrapper<>();
     String messageCode = query.getInfo().getMessageCode();
     if (StringUtils.isNotEmpty(messageCode)) {
         queryWrapper.like("message_code", messageCode);
     }
     queryWrapper.orderByDesc("create_time");
     IPage<MessageTemplateVO> result = PageHelp.siamplePage(this, queryWrapper,query.getPage(),MessageTemplateVO.class);
     return Response.success(result);
 }

 /**
  * 新增
  */
 public Response addTemplate(MessageTemplateVO pojo) {
 	MessageTemplateEntity infoBean =  DozerBeanUtil.map(pojo, MessageTemplateEntity.class);
     infoBean.setUuid(UUIDUitl.UUID32(false));
     infoBean.setCreateTime(new Date());
     infoBean.setUpdateTime(new Date());
     this.save(infoBean);
     return Response.success();
 }

 /**
  * 编辑
  */
 public Response updateTemplate(MessageTemplateVO pojo) {
 	MessageTemplateEntity infoBean =  DozerBeanUtil.map(pojo, MessageTemplateEntity.class);
 	infoBean.setUpdateTime(new Date());
 	return Response.success(this.updateById(infoBean));
 }

 /**
  * 删除
  */
 public Response deleteTemplate(String uuid) {
 	 return Response.success(this.removeById(uuid));
 }
 
}
